<template>
  <div>
    <!--采购记录-->
    <el-table
      :data="tableData"
      stripe
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="采购员"
        width="180">
      </el-table-column>
      <el-table-column
        prop="namea"
        label="审核员"
        width="180">
      </el-table-column>
      <el-table-column
        prop="bookname"
        label="图书"
        width="180">
      </el-table-column>
      <el-table-column
        prop="quantity"
        label="预计商品采购数"
        width="180">
      </el-table-column>
      <el-table-column
        prop="price"
        label="采购总价"
        width="180">
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.state == 1">审核通过</span>
          <span v-if="scope.row.state == 2">采购成功</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="budget"
        label="预计总价"
        width="180">
      </el-table-column>
      <el-table-column
        prop="realityamount"
        label="实际采购数"
        width="180">
      </el-table-column>
      <el-table-column
        prop="realityprice"
        label="实际采购价格"
        width="180">
      </el-table-column>
      <el-table-column
        prop="date" :formatter="dateFormat"
        label="采购单创建时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="amount"
        label="入库数量"
        width="180">
      </el-table-column>
      <el-table-column
        prop="remark"
        label="备注"
        width="180">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button @click="dialogFormVisible=true;audit=scope.row" type="primary"
                     icon="el-icon-edit" size="small">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="信息" :visible.sync="dialogFormVisible">
      <el-form>
        <el-form-item label="采购员">
          <el-select v-model="audit.uid" placeholder="请选择" disabled="">
            <el-option v-for="item in user" :label="item.name" :key="item.uid" :value="item.uid"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="图书">
          <el-select v-model="audit.book" placeholder="请选择" disabled="">
            <el-option v-for="item in bookfind" :label="item.name" :key="item.id" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预计商品数量" >
          <el-input v-model="audit.quantity" style="width: 260px" disabled=""></el-input>
        </el-form-item>

        <el-form-item label="采购总价" >
          <el-input v-model="audit.price" style="width: 260px" disabled=""></el-input>
        </el-form-item>
        <el-form-item label="预计商品采购总价" >
          <el-input v-model="audit.budget" style="width: 260px" disabled=""></el-input>
        </el-form-item>
        <el-form-item label="审核员">
          <el-select v-model="audit.auditor" placeholder="请选择" disabled="">
            <el-option v-for="item in auditor" :label="item.name" :key="item.uid" :value="item.uid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核状态....">
          <template>
            <el-select v-model="audit.state" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </template>
        </el-form-item>

        <el-form-item label="实际采购数量">
          <el-input v-model="audit.realityamount" style="width: 260px" disabled=""></el-input>
        </el-form-item>
        <el-form-item label="实际采购总价">
          <el-input v-model="audit.realityprice" style="width: 260px" disabled=""></el-input>
        </el-form-item>

        <el-form-item label="实际采购时间">
          <el-date-picker
            v-model="audit.date"
            type="datetime"
            placeholder="选择日期时间" disabled="">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="实际入库数量">
          <el-input v-model="audit.amount" style="width: 260px" disabled=""></el-input>
        </el-form-item>

        <el-form-item label="备注">
          <el-input type="textarea" v-model="audit.remark"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="upd()">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
export default {
  name: "Purchasingapproval",
  data(){
    return{
      tableData:[],
      dialogFormVisible:false,
      audit:{},
      user: [],
      bookfind:[],
      options: [ {
        value: '3',
        label: '入库'
      },{
        value: '2',
        label: '取消选择'
      }
      ],
      auditor:[]
    }
  },
  created() {
    this.find()
    this.userfind()
    this.findbook()
    this.findauditor()
  },
  methods:{
    find(){
      this.$http.post('backservice/applydate/select3').then(data=>{
        this.tableData=data
      })
    },
    userfind(){
      this.$http.post('backservice/user/finduser').then(data=>{
        this.user=data
      })
    },
    findbook(){
      this.$http.post('backservice/book/find1').then(data=>{
        this.bookfind=data
      })
    },
    findauditor(){
      this.$http.post('backservice/user/findauditor').then(data=>{
        this.auditor=data
      })
    },
    dateFormat(row, column, cellValue, index) {
      const daterc = row[column.property]
      if (daterc != null) {
        var date = new Date(daterc);
        var year = date.getFullYear();
        /* 在日期格式中，月份是从0开始，11结束，因此要加0
         * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
         * */
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        // 拼接
        return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
      }
    },
    upd(){
      this.dialogFormVisible=false
      this.$http.post('backservice/applydate/upd',this.audit).then(data=>{
        if (data>0){
          alert("入库成功")
          this.find()
          this.$http.post('backservice/applydate/putinstorage',{num:this.audit.amount,book:this.audit.book})
        }else {
          alert("入库失败")
        }
      })
    }

  }
}
</script>

<style scoped>

</style>
